﻿@using KelonProud
@using KelonProud.Mvc.Models
@model KelonProud.Administration.Dtos.RoleInputDto

@{
    Layout = "~/Views/Shared/_EditMaster.cshtml";
}

<div class="box from-box modal-box">
    <form class="form-horizontal" id="EditForm" name="EditForm" validate method="post" role="form">
        @Html.HiddenFor(f => f.Id)
        @Html.HiddenFor(f => f.TenantId)
        <div class="box-body">
            <ul class="nav nav-tabs tab-nav-right" role="tablist">
                <li role="presentation" class="active"><a href="#edit-navigation-details" data-toggle="tab">角色基础信息</a></li>
                <li role="presentation"><a href="#edit-user-roles" data-toggle="tab">关联菜单信息</a></li>
            </ul>

            <div class="tab-content">
                <div role="tabpanel" class="tab-pane animated fadeIn active" id="edit-navigation-details">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">角色名称</label>
                        <div class="col-sm-10">
                            @Html.TextBoxFor(f => f.DisplayName, new { @class = "form-control validate" })
                            <span class="help-block m-b-none">角色名称长度不能小于4个字符且不能超过20个字符，必须填写</span>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">角色编号</label>
                        <div class="col-sm-10">
                            @Html.TextBoxFor(f => f.Name, new { @class = "form-control validate" })
                            <span class="help-block m-b-none">角色编号长度不能小于4个字符且不能超过20个字符，必须填写</span>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">备注</label>
                        <div class="col-sm-10">
                            @Html.TextAreaFor(f => f.Description, new { @class = "form-control" })
                        </div>
                    </div>
                </div>
                <div role="tabpanel" class="tab-pane animated fadeIn" id="edit-user-roles">
                    <ul id="navTree" class="ztree" style="padding-top:-10px"></ul>
                </div>
            </div>
        </div>
        @Html.Partial("~/Views/Shared/Modals/_ModalFooterWithSaveAndCancel.cshtml")
    </form>
</div>

@section styles {
    <style>
    </style>
}

@section scripts{
    <script>
        $(function() {
            loadTree();
        });

        function loadTree() {
            var setting2 = {
                view: {
                    showLine: true,
                    selectedMulti: true
                },
                data: {
                    key: {
                    },
                    simpleData: {
                        enable: true,
                        iconSkin: "iconSkin"
                    }
                },
                check: {
                    enable: true
                }
            }

            abp.ajax({
                url: '/api/services/admin/navigation/GetNavigationRoleTreeJson?roleid=@Model.Id'
            }).done(function(data) {
                $.fn.zTree.init($("#navTree"), setting2, data);

            });
        }

        function saveFormEvent(_$form) {
            var _navService = abp.services.admin.role;
            var role = _$form.serializeFormToObject(); //serializeFormToObject is defined in main.js
            role.navigationIds = [];


            var treeObj = $.fn.zTree.getZTreeObj("navTree");
            var selectnodes = treeObj.getCheckedNodes();

            if (selectnodes) {
                for (var i = 0; i < selectnodes.length; i++) {
                    role.navigationIds.push(selectnodes[i].id);
                }
            }

            abp.ui.setBusy(_$form);
            _navService.save(role).done(function() {
                if (role.Id === 0) {
                    abp.notify.success("角色创建成功！");
                } else {
                    abp.notify.success("角色修改成功！");
                }

                DiyWindow.closeModal();

            }).always(function() {
                abp.ui.clearBusy(_$form);
            });
        }
    </script>
}